package com.example.consumer.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.provider.entity.User;
import com.example.provider.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

@RestController
public class UserController {

    @Reference(version = "1.0.0",timeout = 3000)
    UserService userService;

    @RequestMapping("insert")
    public String insert(){
        User user=new User();
        user.setId(Integer.valueOf("10"));
        user.setEmail("10");
        user.setUsername("10");
        user.setPhone("10");
        userService.insertUser(user);
        return "SUCCESS";
    }

    @RequestMapping("delete")
    public String delete(Integer id){
        userService.deleteUser(id);
        return "SUCCESS";
    }

    @RequestMapping("update")
    public String update(User user){
        userService.updateUser(user);
        return "SUCCESS";
    }

    @RequestMapping("getStudent")
    public List<User> getUser(){
        return userService.getUser();
    }

    @RequestMapping("userId")
    public Optional<User> getUserById(Integer id){
        return userService.getUserById(id);
    }
}
